﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace DAO
{
    public class PhieuChi_DAO
    {
        private static PhieuChi_DAO m_instance = null;

        public static PhieuChi_DAO Instance
        {
            get
            {
                if (m_instance == null)
                    m_instance = new PhieuChi_DAO();
                return m_instance;
            }
        }

        /// <summary>
        ///   lay ma phieu chi 
        /// </summary>
        /// 

        public DataTable LayMaPhieuChi()
        {
            DataTable result = new DataTable();
            try
            {
                SqlConnection cnn = SQLConnection.Instance.SqlConnection;
                SqlCommand cmd = new SqlCommand("GET_LAYMAPHIEUCHI_MAX", cnn);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(result);
                return result;
            }
            catch (System.Exception ex)
            {
                return null;
            }
        }

        /// <summary>
        ///   Them phieu chi
        /// </summary>
        /// 

        public bool ThemPhieuChi(string _maphieuchi, DateTime _ngayChi, long _tongTien)
        {
            try
            {
                SqlConnection cnn = SQLConnection.Instance.SqlConnection;
                SqlCommand cmd = new SqlCommand("ADD_PHIEUCHI", cnn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@MaPhieuChi", SqlDbType.NVarChar, 10);
                cmd.Parameters["@MaPhieuChi"].Value = _maphieuchi;

                cmd.Parameters.Add("@NgayChi", SqlDbType.SmallDateTime);
                cmd.Parameters["@NgayChi"].Value = _ngayChi.ToShortDateString();

                cmd.Parameters.Add("@TongTien", SqlDbType.Money);
                cmd.Parameters["@TongTien"].Value = (decimal)_tongTien;

                cmd.ExecuteNonQuery();
                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }
    }
}
